<template>
  <div>
    <div>
      <h4>1. 查询所有图书信息</h4>
      <button @click="allFn">查询-看控制台</button>
    </div>
    <div>
      <h4>2. 查询某本图书信息</h4>
      <input type="text" placeholder="输入要查询的书名" v-model="bookName" />
      <button @click="selFn">查询-看控制台</button>
    </div>
    <div>
      <h4>3. 新增图书信息</h4>
      <input type="text" placeholder="书名" v-model="obj.bookname"/>
      <input type="text" placeholder="作者" v-model="obj.author"/>
      <input type="text" placeholder="出版社" v-model="obj.publisher"/>
    </div>
    <button @click="addFn">点击新增图书</button>
  </div>
</template>

<script>
import axios from "axios";
axios.defaults.baseURL = "http://123.57.109.30:3006"
export default {
  data() {
    return {
      bookName: "",
      obj: {
          bookname: "",
          author: "",
          publisher: ""
      }
    };
  },
  methods: {
    allFn() {
      axios({
        method: "get",
        url: "/api/getbooks",
      }).then(function (res) {
        console.log(res);
      });
    },
    selFn() {
      axios({
        method: "get",
        url: "/api/getbooks",
        params: {
          bookname: this.bookName,
        },
      }).then(function (res) {
        console.log(res);
      });
    },
    addFn(){
        axios({
            method: "POST",
            url: "/api/addbook",
            data: {
                appkey: "7250d3eb-18e1-41bc-8bb2-11483665535a",
                ...this.obj
            }
        }).then(res => {
            console.log(res);
        })
    }
  },
};
</script>

<style>
</style>